package com.tencent.sr.iris.basic.saas.common.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;
import java.util.Optional;

/**
 * 子任务考核门槛类型 1=GMV,2=佣金,3=有效分享数，4=销售件数，5=分销单数
 */
@Getter
public enum AssessmentThresholdTypeEnum {
    
    GMV(1, "GMV"),

    COMMISSION(2, "佣金"),

    VALID_SHARE_NUM(3, "有效分享数"),

    SALE_NUM(4, "销售件数"),

    DISTRIBUTION_ORDER_NUM(5, "分销单数"),
    ;

    /**
     * 子任务考核门槛类型
     */
    private Integer code;

    /**
     * 描述
     */
    private String desc;

    AssessmentThresholdTypeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getDescByCode(Integer code) {
        AssessmentThresholdTypeEnum enumByType = getEnumByCode(code);
        return Optional.ofNullable(enumByType)
                .map(AssessmentThresholdTypeEnum::getDesc).orElse(StringUtils.EMPTY);
    }

    public static AssessmentThresholdTypeEnum getEnumByCode(Integer code) {
        for (AssessmentThresholdTypeEnum typeEnum : AssessmentThresholdTypeEnum.values()) {
            if (Objects.equals(typeEnum.getCode(), code)) {
                return typeEnum;
            }
        }
        return null;
    }
}
